Recursion Is a Computational Eeect Recursion Is a Computational Eeect
نویسندگان
چکیده
In a recent paper, Launchbury, Lewis, and Cook observe that some Haskell applications could bene t from a combinator m x for expressing recursion over monadic types. We investigate three possible de nitions of m x and implement them in Haskell. Like traditional xpoint operators, there are two approaches to the de nition of m x: an unfolding one based on mathematical semantics, and an updating one based on operational semantics. The two de nitions are equivalent in pure calculi but have di erent behaviors when used within monads. The unfolding version can be easily de ned in Haskell if one restricts xpoints to function types. The updating version is much more challenging to dene in Haskell despite the fact that its de nition is straightforward in Scheme. After studying the Scheme de nition in detail, we mirror it in Haskell using the primitive unsafePerformIO. The resulting de nition of m x appears to work well but proves to be unsafe, in the sense that it breaks essential properties of the purely functional subset of Haskell. We conclude that the updating version of m x should be treated as a monadic e ect. This observation leads to a safe de nition based on monad transformers that pinpoints and exposes the subtleties of combining recursion with other e ects and puts them under the programmer's control to resolve as needed. The conclusion is that Haskell applications that need the functionality of m x can be written safely in any Haskell dialect that supports the multiparameter classes necessary for de ning monad transformers. No other extensions to standard Haskell are needed, although some syntactic abstractions and libraries can make the task of writing recursive monadic bindings much more convenient. Supported by National Science Foundation Grant number CCR-9733088. Work started at the University of Oregon.
منابع مشابه
Innnitary Self Reference in Learning Theory 1
Kleene's Second Recursion Theorem provides a means for transforming any program p into a program e(p) which rst creates a quiescent self copy and then runs p on that self copy together with any externally given input. e(p), in eeect, has complete (low level) self knowledge, and p represents how e(p) uses its self knowledge (and its knowledge of the external world). Innnite regress is not requir...
متن کاملMonadic Corecursion |deenition, Fusion Laws, and Applications|
This paper investigates corecursive deenitions which are at the same time monadic. This corresponds to functions that generate a data structure following a corecursive process, while producing a computational eeect modeled by a monad. We introduce a functional, called monadic anamorphism, that captures deenitions of this kind. We also explore another class of monadic recursive functions, corres...
متن کاملLower Bounds on Type Checking Overloading
Smith has proposed an elegant extension of the ML type system for polymor-phic functional languages with overloading. Type inference in his system requires solving a satissability problem that is undecidable if no restrictions are imposed on overloading. This short note explores the eeect of recursion and the structure of type assumptions in overloadings on the problem's complexity.
متن کاملTailoring Consistent Specializations as a Natural Approach to Consistency Enforcement (Extended Abstract)
Consistency enforcement may be regarded as a process of transaction transformation , where the modiied transaction will be consistent with respect to a given set of constraints. The computational approach by Schewe and Thalheim requires the modiied transaction to be the greatest consistent one below the original transaction with respect to some order. The order should express the preservation o...
متن کاملImplementation of the Typed Call - by - Value - calculus using a Stack ofRegionsMads
We present a translation scheme for the polymorphi-cally typed call-by-value-calculus. All runtime values , including function closures, are put into regions. The store consists of a stack of regions. Region inference and eeect inference are used to infer where regions can be allocated and de-allocated. Recursive functions are handled using a limited form of polymor-phic recursion. The translat...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2000